﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Axa.CasinoApp.Client.ProcessLayer.Dto;

namespace Axa.CasinoApp.Client.ProcessLayer.UseCases
{
    public class GameUseCaseMock : IGameUseCase
    {
        private readonly int MAX_NUMBER = 7;

        public void GetPotAsync()
        {
            GetPotResponse response; 
            Random rand = new Random();
            if (rand.Next(1, 3) == 0)
            {
                // 33.33333333333333333333333% Chance zu gewinnen
                int number = rand.Next(1, MAX_NUMBER);
                response = new GetPotResponse()
                {
                    NumberRow1 = number,
                    NumberRow2 = number,
                    NumberRow3 = number,
                    HasPlayerWon = true
                };
            }
            else
            {
                response = new GetPotResponse()
                {
                    NumberRow1 = rand.Next(1, MAX_NUMBER),
                    NumberRow2 = rand.Next(1, MAX_NUMBER),
                    NumberRow3 = rand.Next(1, MAX_NUMBER),
                    HasPlayerWon = false
                };
                if (response.NumberRow1 == response.NumberRow2 && response.NumberRow2 == response.NumberRow3)
                {
                    response.NumberRow2 = response.NumberRow3 >= MAX_NUMBER ? response.NumberRow3-- : response.NumberRow3++;
                }
            }
            OnGetPotRequestCompleted(new GetPotResponseEventArgs(response));
        }

        public event EventHandler<GetPotResponseEventArgs> GetPotRequestCompleted;

        public void InitializeGameAsync(int numberOfPlayers)
        {
            OnInitializeGameRequestCompleted();
        }

        public event EventHandler InitializeGameRequestCompleted;

        private void OnInitializeGameRequestCompleted()
        {
            EventHandler handler = InitializeGameRequestCompleted;
            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }

        private void OnGetPotRequestCompleted(GetPotResponseEventArgs e)
        {
            EventHandler<GetPotResponseEventArgs> handler = GetPotRequestCompleted;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }
}
